<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>利用对象封装自己的数学对象 里面有 PI 最大值和最小值</title>
  </head>

  <body>

  </body>
  <script>
    /* 
    利用对象封装自己的数学对象 里面有 PI 最大值和最小值
    */
    //1.构造函数
    /*  function MyMath() {
       this.PI = 3.1415926;
       this.max = function (maxArr) {
         var max = maxArr[0];
         for (let i = 0; i < maxArr.length; i++) {
           if (max <= maxArr[i]) {
             max = maxArr[i];
           }
         }
         return max
       };
       this.min = function (minArr) {
         var min = minArr[0];
         for (let i = 0; i < minArr.length; i++) {
           if (min >= minArr[i]) {
             min = minArr[i];
           }
         }
         return min
       }
     }
     var m1 = new MyMath()
     console.log(m1.PI);
     console.log(m1.max([1, -20, 30]));
     console.log(m1.min([1, -20, 30])); */

    //对象：
    var MyMath = {
      PI: 3.1415,
      max: function (maxArr) {
        var max = maxArr[0];
        for (let i = 0; i < maxArr.length; i++) {
          if (max <= maxArr[i]) {
            max = maxArr[i];
          }
        }
        return max
      },
      min: function (minArr) {
        var min = minArr[0];
        for (let i = 0; i < minArr.length; i++) {
          if (min >= minArr[i]) {
            min = minArr[i];
          }
        }
        return min
      }
    }
    console.log(MyMath.PI);
    console.log(MyMath.max([5, -6, 10, 30, 40]));
    console.log(MyMath.min([5, -6, 10, 30, 40]));
  </script>

</html>